package secondriver.springsubway.example.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class HelloWorldSimpleController extends AbstractController {

	private String viewName;

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, String> model = new HashMap<String, String>(5);
		String name = request.getParameter("name");
		if (StringUtils.isEmpty(name)) {
			model.put("name", "Spring Framework MVC");
		} else {
			model.put("name", name);
		}
		model.put("time", new Date().toString());
		ModelAndView modelAndView = new ModelAndView(getViewName(), model);
		return modelAndView;
	}

	public String getViewName() {
		return viewName;
	}

	public void setViewName(String viewName) {
		this.viewName = viewName;
	}
}
